package main

import "fmt"

type Book struct {
	title   string
	author  string
	subject string
	press   string
}

func main() {

	//showPrint()

	access()
}

// 访问结构体成员
func access() {
	var bookGo Book
	var bookPython Book

	bookGo.title = "Go Web编程实战派-从入门到精通"
	bookGo.author = "廖显东"
	bookGo.subject = "Go语言教程"
	bookGo.press = "电子工业出版社"

	bookPython.title = "Python 教程xxx"
	bookPython.author = "张三"
	bookPython.subject = "Python 语言教程"
	bookPython.press = "xxx出版社"

	//打印bookGo信息
	printBook(&bookGo)
	//打印bookPython信息
	printBook(&bookPython)

}

func printBook(book *Book) {
	fmt.Printf("book title:%s\n", book.title)
	fmt.Printf("book author:%s\n", book.author)
	fmt.Printf("book subject:%s\n", book.subject)
	fmt.Printf("book press:%s\n", book.press)

}

/*
新对象赋值 打印
*/
func showPrint() {
	//创建一个新的结构体  也可以使用key=> value 格式(可省)
	fmt.Println(Book{"Go Web编程实战派-从入门到精通", "廖显东", "go语言教程", "电子工业出版社"})
	//忽略的字段为0 或空
	fmt.Println(Book{title: "Go Web编程实战派-从入门到精通", author: "廖显东"})
}
